StatusEntityManager<TContext, TEntity, TId, TStatusType>

A Manager inheriting from that contains reusable logic for updating a TEntity’s current Status.

Syntax

public abstract class StatusEntityManager<TContext, TEntity, TId, TStatusType> : IdentifiableEntityManager<TContext, TEntity, TId> where TContext : DbContext where TEntity : class, IIdentifiable<TId>, IHasStatus<TStatusType> where TId : struct where TStatusType : class, IDbStatusEnum

Inheritance

Constructors

StatusEntityManager

protected StatusEntityManager(TContext dataContext, IMessagePublisher messagePublisher)
Initializes a new instance of the StatusEntityManager class.

Parameters

  • dataContext TContext: The instance to use for the database connection. Should be injected by the DI container.
  • messagePublisher IMessagePublisher: The SimpleMessageBus instance to use to publish Messages to a Queue. Should be injected by the DI container.

Properties

StatusTypes

public List<TStatusType> StatusTypes { get; }
Gets the collection of active status types available for entities managed by this manager. This collection is populated during initialization from the database.

Returns

List<TStatusType>

Methods

Initialize

public virtual void Initialize()
Initializes the StatusTypes collection by loading active status types from the database. This method is called automatically by status update methods if the collection is empty.

UpdateStatusAsync

public Task<bool> UpdateStatusAsync(TEntity entity, int sortOrder)
Updates the entity’s status to the status type with the specified sort order. Logs the status transition for tracking purposes.

Parameters

  • entity TEntity: The entity to update.
  • sortOrder int: The sort order of the target status type.

Returns

Task<bool> True if the status was successfully updated; otherwise, false.

Exceptions

  • [Exception](https://learn.microsoft.com/dotnet/api/system.exception): Thrown when no status type is found with the specified sort order.